<?php

/**
 * This is the model class for table "{{Node}}".
 *
 * The followings are the available columns in table '{{Node}}':
 * @property integer $node_id
 * @property integer $p_id
 * @property string $node_code
 * @property string $controller
 * @property string $node_name
 * @property string $node_url
 * @property integer $sort
 * @property integer $status
 */
class Node extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Node the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{Node}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('controller', 'required'),
			array('p_id, sort, status', 'numerical', 'integerOnly'=>true),
			array('node_code', 'length', 'max'=>100),
			array('controller', 'length', 'max'=>50),
			array('node_name', 'length', 'max'=>45),
			array('node_url', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('node_id, p_id, node_code, controller, node_name, node_url, sort, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'node_id' => 'Node',
			'p_id' => 'P',
			'node_code' => 'Node Code',
			'controller' => 'Controller',
			'node_name' => 'Node Name',
			'node_url' => 'Node Url',
			'sort' => 'Sort',
			'status' => 'Status',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('node_id',$this->node_id);
		$criteria->compare('p_id',$this->p_id);
		$criteria->compare('node_code',$this->node_code,true);
		$criteria->compare('controller',$this->controller,true);
		$criteria->compare('node_name',$this->node_name,true);
		$criteria->compare('node_url',$this->node_url,true);
		$criteria->compare('sort',$this->sort);
		$criteria->compare('status',$this->status);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}